package com.sddz.pacs.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sddz.pacs.dto.JsonResult;
import com.sddz.pacs.entity.HealthUser;
import com.sddz.pacs.entity.SysUser;
import com.sddz.pacs.service.HealthUserService;
import com.sddz.pacs.service.SysUserService;
import com.sddz.pacs.service.UserResultService;
import com.sddz.pacs.support.ResultConstant;
import com.sddz.pacs.util.ShiroUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author SunLi
 * @Date 2018/9/25
 */
@RestController
@RequestMapping("/superConservator")
@Api(description = "服务站相关接口")
public class SuperConservatorController {


    @Autowired
    private HealthUserService healthUserService;

    @Autowired
    private SysUserService  sysUserService;


    @PostMapping(value = "/index")
    @ApiOperation(value="首页", notes="首页")
    @ApiImplicitParam(name = "",value = "超级管理员获取桥东和桥西总人数",required = true)
    public JsonResult index() throws Exception {
        Map  healthUser = new HashMap<>();
        //获取当前登陆场对象
        SysUser sysUser= ShiroUtils.getUserEntity();
        //超级管理员 获取所有数据
        if(sysUser.getLevels()==0){
            healthUser=  healthUserService.mangerNumber();
        }
        return JsonResult.success(healthUser,ResultConstant.RESIDENT_MESS_SUCCESS);

    }
    @PostMapping(value = "/getByManWomanNum")
    @ApiOperation(value="首页统计男女", notes="查询首页所有男女数量")
    @ApiImplicitParam(name = "",value = "超级管理员统计男女",required = true)
    public JsonResult getByManWomanNum() throws Exception {
        //获取当前登陆场对象
        SysUser sysUser= ShiroUtils.getUserEntity();
        Map<String,Object>  num = new HashMap<>();
        if(sysUser.getLevels()==0){
            num = healthUserService.getManger();
        }
        return JsonResult.success(num,ResultConstant.WAN_WOMAN_NUM_SUCCESS);
    }
    @PostMapping(value = "/getMap")
    @ApiOperation(value = "统计邢台市各地区居民数",notes="统计邢台市各地区居民数")
    @ApiImplicitParam(name = "",value = "居民用户json对象",required = true)
    public JsonResult getMapData() throws  Exception{
        //获取当前登陆场对象
        SysUser sysUser = ShiroUtils.getUserEntity();
        Map<String,Integer> num = new HashMap<>();
        if (sysUser.getLevels() == 0) {
            num =healthUserService.getMapData();
        }
        return JsonResult.success(num,ResultConstant.GET_MAP);
    }
    @PostMapping(value = "/getCountAllStation")
    @ApiOperation(value="统计一年中每个月数据", notes="统计一年中每个月数据")
    @ApiImplicitParam(name = "",value = "",required = true)
    public JsonResult getYearEveryMonth() throws Exception {
        //获取当前登陆场对象
        SysUser sysUser = ShiroUtils.getUserEntity();
        List<Map<String, Object>> num = null;
        if (sysUser.getLevels() == 0) {
            num =healthUserService.getLastData();
        }
        return JsonResult.success(num, ResultConstant.LAST_STATION_DATA_SUCCESS);
    }
    @PostMapping(value = "/getSevenDay")
    @ApiOperation(value="统计七天数据", notes="服务站统计七天数据")
    @ApiImplicitParam(name = "",value = "统计七天数据json数据",required = true)
    public JsonResult getSevenDay()throws Exception {
        //获取当前登陆场对象
        SysUser sysUser = ShiroUtils.getUserEntity();
        List<Map> map = null;
        if (sysUser.getLevels() == 0) {
            map = healthUserService.getMangerSevenDay();
        }
        return JsonResult.success(map, ResultConstant.STATION_DATA_SUCCESS);
    }
    //超级管理员树形结构
    @PostMapping("/treeList")
    @ApiOperation(value = "获取超级管理员树形结构")
    @ApiImplicitParam()
    public JsonResult list() {
        EntityWrapper<SysUser> ew = new EntityWrapper<>();
        List<SysUser> list = sysUserService.selectList(ew);
        return JsonResult.success(list, ResultConstant.GET_TREE_VIEW_SUCCESS);
    }

}
